/* 
 Data: 2020/10/10 12:30
 Author: Danyhug
 Version: 0.0.1
 */

// 按钮列表

// 定时器是否在执行
var isNowTimer = false,
	// 是否在显示
	showing = false,
	chartBtnTemp = 0;

// 隐藏侧边栏
function turnItemBtn() {
	var ItemBtn = document.getElementsByClassName("item-btn")[0];
	var side = document.getElementById("side"),
		body = document.getElementById("body"),
		footer = document.getElementById("footer");
	// 定时器没有在执行
	if (!isNowTimer) {
		if (ItemBtn.innerText != "") {
			// 显示
			showing = true;
			setTimeout(function() {
				showing = false;
			}, 1000);
			ItemBtn.style.transform = "rotate(0deg)";
			ItemBtn.innerText = "";
			side.style.display = "block";
			side.className = "layui-side layui-bg-black side-show";
			body.style.left = 200 + "px";
			footer.style.left = 200 + "px";
			setTimeout(function() {
				resizeChart(chartBtnTemp);
			}, 1000)
		} else {
			// 隐藏
			if (!showing) {
				ItemBtn.style.transform = "rotate(360deg)";
				ItemBtn.innerText = "";
				var timer = function() {
					// 第一次进来为false 所以会执行
					isNowTimer = true;
					console.log("执行前" + isNowTimer);
					setTimeout(function() {
						side.style.display = "none";
						isNowTimer = false;
					}, 1000);
				}();
				side.className = "layui-side layui-bg-black side-hidd";
				body.style.left = 0;
				footer.style.left = 0;
				setTimeout(function() {
					resizeChart(chartBtnTemp);
				}, 900)
			}
		}
	}
}

// js防抖
function debounce(fn, wait) {
	var timeout = null;
	return function() {
		if (timeout !== null) clearTimeout(timeout);
		timeout = setTimeout(fn, wait);
	}
}

// js节流
var throttle = function(func, delay) {
	var timer = null;
	return function() {
		var context = this;
		var args = arguments;
		if (!timer) {
			timer = setTimeout(function() {
				func.apply(context, args);
				timer = null;
			}, delay);
		}
	}
}
